<?php

/**
 * Louder Cache
 *
 * LICENSE
 *
 * This source file is subject to the New BSD License that is bundled
 * with this package in the file docs/LICENSE.txt.
 *
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to info@loudertechnology.com so we can send you a copy immediately.
 *
 * @category Louder
 * @package ClusterNode
 * @copyright Copyright (c) 2005-2009 Andres Felipe Gutierrez (gutierrezandresfelipe at gmail.com)
 * @license New BSD License
 */

/**
 * Servidor que administrar las peticiones al cluster
 *
 * @category Louder
 * @package ClusterNode
 * @copyright Copyright (c) 2005-2009 Andres Felipe Gutierrez (gutierrezandresfelipe at gmail.com)
 * @license New BSD License
 */
class ClusterNode {

	/**
	 * Nombre del Nodo
	 *
	 * @var string
	 */
	private $_name;

	/**
	 * Direccion IP ó nombre del host
	 *
	 * @var string
	 */
	private $_address;

	/**
	 * Protocolo de conexion
	 *
	 * @var string
	 */
	private $_protocol;

	/**
	 * Constructor de ClusterNode
	 *
	 * @param array $descriptor
	 */
	public function __construct($descriptor){
		if(!isset($descriptor['address'])){
			throw new ClusterNodeException("Debe indicar la dirección ó nombre del host del nodo");
		} else {
			$this->_address = $descriptor['address'];
		}
		if(isset($descriptor['name'])){
			$this->_name = $descriptor['name'];
		} else {
			$this->_name = $descriptor['address'];
		}
		if(isset($descriptor['protocol'])){
			$this->_protocol = $descriptor['protocol'];
		} else {
			$this->_protocol = "tcp";
		}
	}

	/**
	 * Obtiene la direccion IP o nombre del host
	 *
	 * @return string
	 */
	public function getAddress(){
		return $this->_address;
	}

	/**
	 * Obtiene la direccion IP o nombre del host
	 *
	 * @return string
	 */
	public function getProtocol(){
		return $this->_protocol;
	}

	/**
	 * Devuelve el nombre del nodo
	 *
	 * @return string
	 */
	public function getName(){
		return $this->_name;
	}

}